package com.yz.group1.group_1.service.impl;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.yz.group1.group_1.entity.Hospitalization;
import com.yz.group1.group_1.mapper.HospitalizationMapper;
import com.yz.group1.group_1.service.HospitalizationService;
import org.springframework.stereotype.Service;
import java.util.Date;
import java.util.List;

@Service
public class HospitalizationServiceImpl extends ServiceImpl<HospitalizationMapper, Hospitalization> implements HospitalizationService {

    // 保存住院申请（自动填充创建时间）
    @Override
    public boolean save(Hospitalization entity) {
        // 自动设置创建时间为当前时间
        if (entity.getCreatedAt() == null) {
            entity.setCreatedAt(new Date());
        }
        return super.save(entity);
    }

    // 根据患者ID查询住院申请
    @Override
    public List<Hospitalization> getHospitalizationsByPatientId(Long patientId) {
        // 实际实现：根据patientId查询数据库
        if (patientId != null) {
            return lambdaQuery()
                    .eq(Hospitalization::getPatientId, patientId)
                    .list();
        } else {
            // 若未传patientId，则返回所有记录
            return list();
        }
    }
}